package com.quick.develop.flowable.framework.core;

import com.quick.develop.flowable.framework.enums.definition.BpmAddendumEnum;
import com.quick.develop.flowable.framework.factory.FlowServiceFactory;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * desc: 流程结束监听
 *
 * @author junyuan.liu
 * @date 2023/6/14 13:25
 */
@Component
@Slf4j
public class BpmProcessCompletedListener extends FlowServiceFactory implements FlowableEventListener {

    @Override
    public void onEvent(FlowableEvent flowableEvent) {
        ExecutionEntityImpl execution = (ExecutionEntityImpl) ((FlowableEntityEventImpl) flowableEvent).getExecution();
        ExecutionEntityImpl superExecution = execution.getSuperExecution();

        // 只考虑主流程结束
        if (Objects.isNull(superExecution)
                && !BpmAddendumEnum.isIgnore(execution.getProcessDefinitionKey())) {
            String businessKey = execution.getBusinessKey();
        }


    }

    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return null;
    }
}
